package com.tomorrow.runner.activity.main;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.tomorrow.runner.R;

/**
 * 主界面抽屉功能列表适配器
 * Created by tomorrow on 16-4-21.
 */
public class DrawerListAdapter extends BaseAdapter {


    private Context mContext;
    private String[] mLabelList;
    private int[] mImgList;
    public DrawerListAdapter(Context context, String[] dataList, int[] imgIds){
        mContext = context;
        mLabelList = dataList;
        mImgList = imgIds;
    }
    @Override
    public int getCount() {
        return mLabelList.length;
    }

    @Override
    public Object getItem(int position) {
        return mLabelList[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String label = mLabelList[position];
        int imgId = mImgList[position];
        ViewHolder viewHolder;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.home_drawer_func_list_item,null);
            viewHolder.icon = (ImageView) convertView.findViewById(R.id.item_img);
            viewHolder.label = (TextView) convertView.findViewById(R.id.item_label);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.icon.setImageResource(imgId);
        viewHolder.label.setText(label);
        return convertView;
    }

    class ViewHolder{
        ImageView icon;
        TextView label;
    }
}
